From ac9beaa56335ce2d089c15d6d6de66ed4c1c467e Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 23 Feb 2004 03:27:06 +0000 Subject: [PATCH] Add poweroff and get current position to garmin. --- gpsbabel/garmin.c | 34 ++++++++++++++++++++++++++++++++-- gpsbabel/jeeps/gpscom.c | 7 +++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/gpsbabel/garmin.c b/gpsbabel/garmin.c index cffe483bd..f23f7075f 100644 --- a/gpsbabel/garmin.c +++ b/gpsbabel/garmin.c @@ -1,7 +1,7 @@ /* Jeeps wrapper for Garmin serial protocol. - Copyright (C) 2002 Robert Lipe, robertlipe@usa.net + Copyright (C) 2002, 2003, 2004 Robert Lipe, robertlipe@usa.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,6 +32,15 @@ static GPS_PWay *tx_routelist; static GPS_PWay *cur_tx_routelist_entry; static GPS_PTrack *tx_tracklist; static GPS_PTrack *cur_tx_tracklist_entry; +static char *getposn; +static char *poweroff; + +static +arglist_t garmin_args[] = { + { "get_posn", &getposn, "Return current position as a waypoint", ARGTYPE_BOOL}, + { "power_off", &poweroff, "Command unit to power itself down", ARGTYPE_BOOL}, + { 0, 0, 0, 0} +}; static void rw_init(const char *fname) @@ -50,6 +59,11 @@ rw_init(const char *fname) } GPS_Enable_Error(); + if (poweroff) { + GPS_Command_Off(fname); + return; + } + if (GPS_Init(fname) < 0) { fatal(MYNAME ":Can't init %s\n", fname); } @@ -120,6 +134,15 @@ waypt_read(void) int i,n; GPS_PWay *way; + if (getposn) { + waypoint *wpt = waypt_new(); + wpt->latitude = gps_save_lat; + wpt->longitude = gps_save_lon; + wpt->shortname = "Position"; + waypt_add(wpt); + return; + } + if ((n = GPS_Command_Get_Waypoint(portname, &way)) < 0) { fatal(MYNAME ":Can't get waypoint from %s\n", portname); } @@ -279,6 +302,10 @@ route_read(void) static void data_read(void) { + if (poweroff) { + return; + } + switch(global_opts.objective) { case trkdata: track_read(); @@ -514,6 +541,9 @@ track_write(void) static void data_write() { + if (poweroff) { + return; + } switch(global_opts.objective) { case wptdata: waypoint_write(); @@ -536,5 +566,5 @@ ff_vecs_t garmin_vecs = { rw_deinit, data_read, data_write, - NULL + garmin_args }; diff --git a/gpsbabel/jeeps/gpscom.c b/gpsbabel/jeeps/gpscom.c index 7ac611aea..235a5c4ea 100644 --- a/gpsbabel/jeeps/gpscom.c +++ b/gpsbabel/jeeps/gpscom.c @@ -39,6 +39,8 @@ int32 GPS_Command_Off(const char *port) GPS_PPacket tra; GPS_PPacket rec; + GPS_Util_Little(); + if(!GPS_Serial_On(port, &fd)) return gps_errno; @@ -46,8 +48,9 @@ int32 GPS_Command_Off(const char *port) return MEMORY_ERROR; GPS_Util_Put_Short(data,COMMAND_ID[gps_device_command].Cmnd_Turn_Off_Pwr); - - GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Command_Data, + + /* robertl - LINK_ID isn't set yet. Hardcode it to Garmin spec value */ + GPS_Make_Packet(&tra, 10, /* LINK_ID[gps_link_type].Pid_Command_Data, */ data,2); if(!GPS_Write_Packet(fd,tra)) return gps_errno; -- 2.30.2